package com.bus.boot.action.member;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.bus.boot.web.Token;
import com.bus.core.entity.BusUser;
import com.bus.core.web.util.BusUtils;
import com.bus.core.web.util.FrontUtils;
import com.bus.core.web.util.URLHelper;

@Controller
public class DynamicPageAct {
	private static final Logger log = LoggerFactory
			.getLogger(DynamicPageAct.class);

	/**
	 * TOMCAT的默认路径
	 * 
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/", method = RequestMethod.GET)
	@Token(save = true)
	public String index(HttpServletRequest request,
			HttpServletResponse response, ModelMap model) {
		// return FrontUtils.getTplPath(request,
		// site.getSolutionPath(),TPLDIR_INDEX, TPL_INDEX);
		// 带有其他路径则是非法请求(非内网)
		String uri = URLHelper.getURI(request);
		if (StringUtils.isNotBlank(uri)
				&& (!(uri.equals("/") || uri.equals("/index.jhtml")))) {
			return FrontUtils.pageNotFound(request, response, model);
		}

		BusUser user = BusUtils.getUser(request);
		if (user != null) {
			return "redirect:/member/index.jspx";
		}

		return "redirect:login.jspx";
	}

}
